<template>
  <div class="wrapper">
    <router-link tag="div" to="/" class="header-abs" v-show="showAbs">
      <div class="iconfont icon-fanhui"></div>
    </router-link>
    <div class="header" v-show="!showAbs" :style="opacityStyle">
      <div class="header-left">
        <router-link to="/"
          ><span class="iconfont icon-fanhui"></span>
        </router-link>
      </div>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'TravelIndex',

  data() {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },

  methods: {
    handleScroll() {
      const top = document.documentElement.scrollTop
      if (top > 160) {
        let opacity = top / 240
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity: opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  mounted() {
    window.addEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="less" scoped>
.icon-fanhui {
  color: #fff;
  font-size: 0.4rem;
}
.header-abs {
  z-index: 99;
  position: absolute;
  left: 0.2rem;
  top: 0.2rem;
  width: 0.8rem;
  height: 0.8rem;
  line-height: 0.8rem;
  border-radius: 0.4rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.8);
}
.header {
  z-index: 2;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;

  font-size: 0.32rem;
  background: #00bcd4;
  color: #fff;
  line-height: 1.1467rem;
  text-align: center;

  .header-left {
    width: 0.8533rem;
    float: left;
  }
}
</style>
